package com.sanji.sjmallutils;

import android.content.Context;
import android.view.WindowManager;

import com.sanji.sjmallconfig.ConfigConts;

/**
 * Created by fhm on 2016/12/13.
 */
public class ImageSizeUtil {
    public static SharePreferenceUtil spUtil;

    public static void getScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = windowManager.getDefaultDisplay().getWidth();
        int height = windowManager.getDefaultDisplay().getHeight();
        if (spUtil == null) {
            spUtil = new SharePreferenceUtil(context);
        }
        spUtil.put(ConfigConts.ScreenWidth, width);
        spUtil.put(ConfigConts.ScreenHight, height);
    }

    /**
     * @param context
     * @return 图片的宽是屏幕宽的三分之一
     */
    public static int setImageWidth(Context context, int i) {
        if (spUtil == null) {
            getScreenSize(context);
        }
        int imageWidth = spUtil.getInt(ConfigConts.ScreenWidth, 0);
        return imageWidth / i;
    }

    /**
     * @param
     * @return 根据图片的高是图片的宽的2/3
     */
    public static int setImageHight(int width) {
        return (width * 2) / 3;
    }

    /**
     * @param
     * @return 根据图片的宽和高一致
     */
    public static int setImageHightSampleWidth(int width) {
        return width;
    }
}
